<?php 
class DomArAnnotationTestCase extends UnitTestCase {

	public function testParserClassRules() {
		
		$annotation = '/**
			* TITLE
			* 
			* SOME
			
			* DESCRIPTION
			*
			* @author Oliver
			* @param String $var
			* @orm  tableName  myTable
			* @orm  database  myDatabase
			* @orm index(a,b,c)
			* @orm unique(a,bd,c)
			* @orm listener beforeInsert beforeInsert
			* @orm listener afterSave afterSave(me,too)
			* @var String
			* @return 10
		';
		$result  = DomArAnnotationParser::parse( $annotation, 'class','test_file',0 );		
		
		$this->assertEqual( $result[0]['tag'], 'orm');
		$this->assertEqual( $result[0]['type'], 'tableName');
		$this->assertEqual( $result[0]['tableName'], 'myTable');
		
		$this->assertEqual( $result[1]['tag'], 'orm');
		$this->assertEqual( $result[1]['type'], 'database');
		$this->assertEqual( $result[1]['database'], 'myDatabase');
		
		$this->assertEqual( $result[2]['tag'], 'orm');
		$this->assertEqual( $result[2]['type'], 'index');
		$this->assertEqual( $result[2]['fields'], array('a','b','c'));
		
		$this->assertEqual( $result[3]['tag'], 'orm');
		$this->assertEqual( $result[3]['type'], 'unique');
		$this->assertEqual( $result[3]['fields'], array('a','bd','c'));
		
		$this->assertEqual( $result[4]['tag'], 'orm');
		$this->assertEqual( $result[4]['type'], 'listener');
		$this->assertEqual( $result[4]['listener'], 'beforeInsert');
		$this->assertEqual( $result[4]['method'], 'beforeInsert');
		$this->assertEqual( $result[4]['args'], array());
		
		$this->assertEqual( $result[5]['tag'], 'orm');
		$this->assertEqual( $result[5]['type'], 'listener');
		$this->assertEqual( $result[5]['listener'], 'afterSave');
		$this->assertEqual( $result[5]['method'], 'afterSave');
		$this->assertEqual( $result[5]['args'], array('me','too'));		
	}

	public function testParserPropertyRules() {
		
		$annotation = '/**
			* TITLE
			* 
			* SOME
			
			* DESCRIPTION
			*
			* @author Oliver
			* @param String $var
			* @orm text
			* @orm boolean
			* @orm boolean unique
			* @orm char(12)
			* @orm char(10) unique
			* @orm float(12,2)
			* @orm float(10,4) unique
			* @orm validator method myMethod([a=10,[c=30]])
			* @orm validator myMethod(_args_)
			* @orm plugin myPlugin(ARGS)
			* @orm has many ClassName inverse Asd
			* @orm owns one ClassName inverse ASd myValidator counter nrOfItems
			* @orm has parent ClassName myValidator(a,b) counter nrOfItems
			* @orm listener beforeInsert beforeInsert
			* @orm listener afterSave afterSave(me,too)
			* @var String
			* @return 10
		';
		$result  = DomArAnnotationParser::parse( $annotation, 'property','test_file',0 );		

		$this->assertEqual( $result[0]['tag'], 'orm');
		$this->assertEqual( $result[0]['type'], 'listener');
		$this->assertEqual( $result[0]['listener'], 'beforeInsert');
		$this->assertEqual( $result[0]['method'], 'beforeInsert');
		$this->assertEqual( $result[0]['args'], array());
		
		$this->assertEqual( $result[1]['tag'], 'orm');
		$this->assertEqual( $result[1]['type'], 'listener');
		$this->assertEqual( $result[1]['listener'], 'afterSave');
		$this->assertEqual( $result[1]['method'], 'afterSave');
		$this->assertEqual( $result[1]['args'], array('me','too'));
		
		$this->assertEqual( $result[2]['tag'], 'orm');
		$this->assertEqual( $result[2]['type'], 'validator');
		$this->assertEqual( $result[2]['validator'], 'myMethod');
		$this->assertEqual( $result[2]['isMethod'], 'method');
		$this->assertEqual( $result[2]['args'], array(array('a'=>10, array('c'=>30))));
		
		$this->assertEqual( $result[3]['tag'], 'orm');
		$this->assertEqual( $result[3]['type'], 'validator');
		$this->assertEqual( $result[3]['validator'], 'myMethod');
		$this->assertEqual( $result[3]['isMethod'], '');
		$this->assertEqual( $result[3]['args'], array('_args_'));
		
		$this->assertEqual( $result[4]['tag'], 'orm');
		$this->assertEqual( $result[4]['type'], 'plugin');
		$this->assertEqual( $result[4]['plugin'], 'myPlugin');
		$this->assertEqual( $result[4]['args'], array('ARGS'));
		
		$this->assertEqual( $result[5]['tag'], 'orm');
		$this->assertEqual( $result[5]['type'], 'has');
		$this->assertEqual( $result[5]['multiplicity'], 'many');
		$this->assertEqual( $result[5]['className'], 'ClassName');
		$this->assertEqual( $result[5]['inverse'], 'Asd');
		$this->assertEqual( $result[5]['itemValidator'], '');
		$this->assertEqual( $result[5]['itemValidatorArgs'], array());
		$this->assertEqual( $result[5]['counter'], '');
		
		$this->assertEqual( $result[6]['tag'], 'orm');
		$this->assertEqual( $result[6]['type'], 'owns');
		$this->assertEqual( $result[6]['multiplicity'], 'one');
		$this->assertEqual( $result[6]['className'], 'ClassName');
		$this->assertEqual( $result[6]['inverse'], 'ASd');
		$this->assertEqual( $result[6]['itemValidator'], 'myValidator');
		$this->assertEqual( $result[6]['itemValidatorArgs'], array());
		$this->assertEqual( $result[6]['nrOfItems'], '');
		
		$this->assertEqual( $result[7]['tag'], 'orm');
		$this->assertEqual( $result[7]['type'], 'has');
		$this->assertEqual( $result[7]['multiplicity'], 'parent');
		$this->assertEqual( $result[7]['className'], 'ClassName');
		$this->assertEqual( $result[7]['inverse'], '');
		$this->assertEqual( $result[7]['itemValidator'], 'myValidator');
		$this->assertEqual( $result[7]['itemValidatorArgs'], array('a','b'));
		$this->assertEqual( $result[7]['nrOfItems'], '');
	
		$this->assertEqual( $result[8]['tag'], 'orm');
		$this->assertEqual( $result[8]['type'], 'text');
		$this->assertEqual( $result[8]['index'], '');
		
		$this->assertEqual( $result[9]['tag'], 'orm');
		$this->assertEqual( $result[9]['type'], 'boolean');
		$this->assertEqual( $result[9]['index'], '');
		
		$this->assertEqual( $result[10]['tag'], 'orm');
		$this->assertEqual( $result[10]['type'], 'boolean');
		$this->assertEqual( $result[10]['index'], 'unique');
		
		$this->assertEqual( $result[11]['tag'], 'orm');
		$this->assertEqual( $result[11]['type'], 'char');
		$this->assertEqual( $result[11]['length'], array('12') );
		$this->assertEqual( $result[11]['index'], '');	
		
		$this->assertEqual( $result[12]['tag'], 'orm');
		$this->assertEqual( $result[12]['type'], 'char');
		$this->assertEqual( $result[12]['length'], array('10'));
		$this->assertEqual( $result[12]['index'], 'unique');

		$this->assertEqual( $result[13]['tag'], 'orm');
		$this->assertEqual( $result[13]['type'], 'float');
		$this->assertEqual( $result[13]['length'], array('12','2'));
		$this->assertEqual( $result[13]['index'], '');
		
		$this->assertEqual( $result[14]['tag'], 'orm');
		$this->assertEqual( $result[14]['type'], 'float');
		$this->assertEqual( $result[14]['length'], array('10','4'));
		$this->assertEqual( $result[14]['index'], 'unique');
		
		
	}

}
?>
